import { defineConfig, loadEnv } from 'vite'
import path from 'path'
import createVitePlugins from './vite/plugins'

// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => {
  const env = loadEnv(mode, process.cwd())
  const { VITE_APP_ENV } = env
  return {
    base: VITE_APP_ENV === 'production' ? '/' : '/',
    plugins: [...createVitePlugins(env, command === 'build')],
    envDir: './vite/env',
    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src')
      }
    },
    server: {
      host: true,
      port: 7077,
      open: true,
      proxy: {
        //https://49h942857d.yicp.fun
        //http://139.224.16.223 云端
        //http://localhost:8080 家化
        //http://localhost:8001/ QS DEV
        '/api': {
          target: 'http://localhost:8001/',
          changeWOrigin: true,
          //rewrite: (p) => p.replace(/^\/prod-api/, '')
        }
      }
    },
  }
})
